<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");

$errMsg = "";
if(sxREQ("reqtype") == "save"){
	$errMsg .= libraryIns();
}

$aOpz = array("kMenu"=>'pro.fun', "isReloadable"=>false);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
function objFrmSubm(rt){
	document.objFrm.reqtype.value = rt;
	document.objFrm.submit();
}
</script>
  
<?php
echo(bodyHTML($aOpz));

$aCmd = array("insMD"=>array("pag"=>"javascript:objFrmSubm('save')",
										"title"=>"save",
										"text"=>"save"
										),
					"back"=>array()
					);
$sCmd = commandsHTML($aCmd);	
echo $sCmd;

echo getHtmlForm('objFrm');
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('reqtype','...');

echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" width=\"20%\" colspan='2'>Library</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Name*</td>" .
			"<td class=\"text01\">".getHtmlText('library',32,32)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Description*</td>" .
			"<td class=\"text01\">".getHtmlText('description',80,80)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Note</td>" .
			"<td class=\"text01\">".getHtmlTextArea('note',80,3)."</td>" .
		"</tr>\n");
echo("</table>");
echo $sCmd;
echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
exit();

function libraryIns($redirOnEnd = true){
	global $objSDAO;
	$errMsg = "";
	if(trim($_REQUEST["library"]) == '')
		$errMsg .= "missing name<br>";
	if(ereg("[^a-zA-Z0-9_]",trim($_REQUEST["library"])))
		$errMsg .= "Name: only letter, number and _<br>";
	if(trim($_REQUEST["description"]) == '')
		$errMsg .= "missing description<br>";
	//existence
	$sSQL = "SELECT count(*) as num FROM library WHERE library='".$_REQUEST["library"]."'";
	$objSDAO->query($sSQL);
	$row = $objSDAO->fetch();
	if ($row['num']>0) {
		$errMsg .= "existing name<br>";
	}		
		
	if($errMsg != ""){
		return $errMsg;
	}
	$sSQL = "INSERT INTO " .
			"library " .
			"(library, " .
			"description, " .
			"note)" .
			"VALUES('".sxRAS("library")."', " .
			"'".sxRAS("description")."', " .
			"'".sxRAS("note")."'" .
			")";			
	$objSDAO->query($sSQL,"ins");
	$url = $_SESSION[USEROBJ]->getHistory(0, true);
	serverRedir($url);
	return 'abnormal end';
}
